package com.cloudptt.wp.ui.more.advanced;

import com.cloudptt.api.comm.CommDlg;
import com.cloudptt.wp.R;

import android.app.ActionBar.LayoutParams;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class InputTextDialog extends DialogFragment {


	private EditText txtname;
	private TextView title;
	private Button btnDone;
	static String DialogboxTitle;
	private String oldtext;
	private int Rid;
	
	public interface InputTextDialogListener {
		void onFinishInputDialog(int rid,String inputText);
		}
	

	//---set the title of the dialog window
	public void setDialogTitle(String title) {
		DialogboxTitle = title;
	}
	
	public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle saveInstanceState){
		
		View view = inflater.inflate(R.layout.input_text_dialogfragment, container);
				
				//---get the EditText and Button views
				txtname = (EditText) view.findViewById(R.id.input_text);
				title = (TextView) view.findViewById(R.id.titleTv);
				btnDone = (Button) view.findViewById(R.id.btnDone);
				
				//---event handler for the button
				btnDone.setOnClickListener(new View.OnClickListener()
				{
					public void onClick(View view) {
					
						if(txtname.length()==0)
						{
							CommDlg.show(getActivity(), "不能为空");
						}
						//---gets the calling activity
						InputTextDialogListener activity = (InputTextDialogListener) getActivity();
						activity.onFinishInputDialog(Rid,txtname.getText().toString());
				
						//---dismiss the alert
						dismiss();
					}
				});
				
				//---show the keyboard automatically
				txtname.requestFocus();
				txtname.setText(oldtext);
				getDialog().getWindow().setSoftInputMode(LayoutParams.MATCH_PARENT);
				title.setText(DialogboxTitle);
				//---set the title for the dialog
//				getDialog().setTitle(DialogboxTitle);
				getDialog().requestWindowFeature(STYLE_NO_TITLE);
		
		return view;	
	}

	public void setRid(int idPositioningInterval) 
	{
		Rid = idPositioningInterval;
		
	}


	public void setOldValue(String text) {

		oldtext = text;
	}
}